package io.renren.modules.erp.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.erp.entity.CustomerPriceEntity;
import io.renren.modules.erp.service.CustomerPriceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 客户报价信息
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-08-11 21:03:16
 */
@RestController
@RequestMapping("erp/customerprice")
public class CustomerPriceController {
    @Autowired
    private CustomerPriceService customerPriceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("erp:customerprice:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = customerPriceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{customerPriceId}")
    @RequiresPermissions("erp:customerprice:info")
    public R info(@PathVariable("customerPriceId") Long customerPriceId){
        CustomerPriceEntity customerPrice = customerPriceService.selectById(customerPriceId);

        return R.ok().put("customerPrice", customerPrice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("erp:customerprice:save")
    public R save(@RequestBody CustomerPriceEntity customerPrice){
        customerPriceService.insert(customerPrice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("erp:customerprice:update")
    public R update(@RequestBody CustomerPriceEntity customerPrice){
        ValidatorUtils.validateEntity(customerPrice);
        customerPriceService.updateAllColumnById(customerPrice);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("erp:customerprice:delete")
    public R delete(@RequestBody Long[] customerPriceIds){
        customerPriceService.deleteBatchIds(Arrays.asList(customerPriceIds));

        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/priceinfo/{customerInfoId}")
    @RequiresPermissions("erp:customerprice:info")
    public R priceinfo(@PathVariable("customerInfoId") Long customerInfoId){
    	List<CustomerPriceEntity> customerPrice = customerPriceService.selectByCustmId(customerInfoId);

        return R.ok().put("customerPriceList", customerPrice);
    }
}
